<template>
  <a-card :bordered="false">
    <search ref="search" :config="searchConfig" @search="search" @getHeight="getHeight"/>
    <div>
      <vxe-grid
        ref="xGrid"
        :border="true"
        :resizable="true"
        :showOverflow="true"
        size="mini"
        :loading="loading"
        :height="pageHeight-seachHeight-94"
        :align="left"
        :columns="columns"
        :data="dataSource"
        :toolbar-config="tableToolbar"
        :checkbox-config="checkboxConfig"
        v-bind="vexConfig"
        @checkbox-change="selectChangeEvent"
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class="table-operator">
            <a-button @click="handleAdd" type="primary">新增</a-button>
          </div>
        </template>
        <template #detail="{ row,rowIndex }">
          <a @click="handleDetail(row)">{{ row.promotionCode }}</a>
        </template>
        <!--       -->
        <!--        <template #status="{ row,rowIndex }">-->
        <!--          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>-->
        <!--        </template>-->
        <template #action="{ row,rowIndex }">
          <a @click="handleEdit(row)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多
              <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handelDeleteAction(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync="ipagination.current"
            :page-size.sync="ipagination.pageSize"
            :total="ipagination.total"
            :pageSizes="ipagination.pageSizeOptions"
            @page-change="handlePageChange">
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>

    <!--      新增促销活动视图-->
    <promotion-modal ref="modalForm" @ok="modalFormOk"></promotion-modal>
    <!--      查看详情-->
    <!--      <DetailWheel ref="details"></DetailWheel>-->
  </a-card>
</template>

<script>
// import DetailWheel from './DetailWheel'
import '@/assets/less/common.less'
import '@/assets/less/TableExpand.less'
import { PageListMixin } from '@/mixins/PageListMixin'
import promotionModal from './modules/promotionModal'
import { getAction, postAction } from '@/api/manage'

export default {
  description: '促销活动页面',
  name: 'promotion',
  mixins: [PageListMixin],
  components: { promotionModal },
  data() {
    return {
      selectionRows: [],
      searchConfig: [
        {
          type: 'input',
          name: 'promotionCode',
          placeholder: '请输入促销编码'
        },
        {
          type: 'input',
          name: 'promotionName',
          placeholder: '请输入促销名称'
        },
        // {
        //   type: 'j-select',
        //   dictCode: 'promtion_template',
        //   name: 'promotionType',
        //   placeholder: '请选择促销模版'
        // },

      ],
      columns: [
        {
          minWidth:60,
          width:60,
          type:'checkbox',
        },
        {
          title: '促销编码',
          align: 'center',
          minWidth: 140,
          field: 'promotionCode',
          slots: { default: 'detail' }
        },
        {
          title: '促销名称',
          align: 'center',
          minWidth: 140,
          field: 'promotionName',
        },
        // {
        //   title: '促销模版',
        //   align: 'center',
        //   minWidth: 100,
        //   field: 'promtionTemplate',
        //   slots: {
        //     default: ({ row }) => {
        //       if (row.promtionTemplate == 1) {
        //         return [<span>搭赠</span>]
        //       } else if (row.promtionTemplate == 2) {
        //         return [<span>满减</span>]
        //       } else if (row.promtionTemplate == 3) {
        //         return [<span>特价</span>]
        //       }
        //     }
        //   }
        // },
        {
          title: '活动时间',
          align: 'center',
          field: 'beginDate',
          minWidth: 300,
          slots: {
            default: ({ row }) => {
              return row.beginDate + ' ～ ' + row.endDate
            }
          }
        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 80,
          field: 'updateTime'
        },
        {
          title: '操作',
          align: 'center',
          field: 'action',
          minWidth: 100,
          slots: { default: 'action' }
        }
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/promotion/dmsPromotion/findPageList',
        delete: window._CONFIG['domianDmsURL'] + '/promotion/dmsPromotion/delete',
        detail: window._CONFIG['domianDmsURL'] + '/promotion/dmsPromotion/getInfo'
      }
    }
  },
  methods: {

    handleToDetail(param, status) {
      // let config = {
      //   title: '活动详情',
      //   minWidth: '70%',
      //   url: { list: window._CONFIG['domianURL'] + '/cnActController/getDetailByIdOrActCode' },
      //   method: getAction,
      //   parms: { id: param }
      // }
      if (!this.url.detail) {
        this.$message.info('请检查详情链接')
        return
      }
      let record = {}
      getAction(this.url.detail, { id: param }).then(res => {
        if (res.code !== 200) {
          this.$message.info('获取数据失败')
          return
        }
        record = res.result
        this.$refs.modalForm.edit(record, status)
      })
    },
    customRowclick(record) {
      return {
        on: {
          click: () => {
            let key = record.id
            let num = this.selectedRowKeys.indexOf(key)
            if (num == -1) {
              this.selectedRowKeys = [key]
              this.selectionRows = [record]
            } else {
              this.selectedRowKeys.splice(num, 1)
              this.selectionRows.splice(num, 1)
            }
          }
        }
      }
    }
  }
}
</script>

<style scoped>

</style>